package org.gvsig.titleblock.swing.impl;

import java.awt.Color;
import java.awt.Graphics;
import java.io.File;
import java.util.HashMap;

import javax.swing.DefaultListModel;
import javax.swing.JFileChooser;
import javax.swing.JPanel;

import org.gvsig.andami.ui.mdiManager.IWindow;
import org.gvsig.andami.ui.mdiManager.WindowInfo;
import org.gvsig.app.ApplicationLocator;
import org.gvsig.app.ApplicationManager;
import org.gvsig.titleblock.IFFrameItem;
import org.gvsig.titleblock.ITBManager;
import org.gvsig.titleblock.ITBToFFrame;
import org.gvsig.titleblock.swing.IJOpenTBPanel;
import org.gvsig.titleblock.swing.ITBSwingManager;

/**
 * This class represents the panel to open a TitleBlock
 * @author Violeta
 *
 */
public class JOpenTBPanel extends IJOpenTBPanel implements IWindow {

	private static String FILECHOOSER_ID = "Open box file";
	private HashMap<String, IFFrameItem> selecteds = new HashMap<String, IFFrameItem>();
	private ITBSwingManager uimanager;
	private ApplicationManager applicationManager;
	private ITBManager manager;
	private ITBToFFrame tbToFframes;
	
	//Initialize the components
	private javax.swing.JButton jButtonCancel;
	private javax.swing.JButton jButtonOpen;
	private javax.swing.JLabel jLabelAuthor;
	private javax.swing.JLabel jLabelDate;
	private javax.swing.JLabel jLabelImage1;
	private javax.swing.JLabel jLabelImage2;
	private javax.swing.JLabel jLabelSubtitle;
	private javax.swing.JLabel jLabelTitle;
	private javax.swing.JList jListTB;
	private javax.swing.JPanel jPanelComponents;
	private javax.swing.JPanel jPanelSelectTB;
	private javax.swing.JScrollPane jScrollPaneTB;
	private javax.swing.JTextField jTextFieldAuthor;
	private javax.swing.JTextField jTextFieldDate;
	private javax.swing.JTextField jTextFieldImage1;
	private javax.swing.JTextField jTextFieldImage2;
	private javax.swing.JTextField jTextFieldSubtitle;
	private javax.swing.JTextField jTextFieldTitle;
	private javax.swing.JButton jButtonOpenFileImage1;
    private javax.swing.JButton jButtonOpenFileImage2;
    private JPanel jPanelView;
	
	/**
	 * This method creates a new form to open a TitleBlock
	 * @param uimanager
	 * @param manager
	 */
	public JOpenTBPanel(ITBSwingManager uimanager, ITBManager manager) {

		this.tbToFframes = manager.getTBToFrame();
		this.uimanager = uimanager;
		this.applicationManager = ApplicationLocator.getManager();
		this.manager = manager;

		initComponents();

	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed"
	// desc="Generated Code">//GEN-BEGIN:initComponents
	private void initComponents() {

		jPanelSelectTB = new javax.swing.JPanel();
		jScrollPaneTB = new javax.swing.JScrollPane();
		jPanelView = new JPanelPreview();
		jPanelView.setBackground(Color.white);
		jListTB = new javax.swing.JList();
		jPanelComponents = new javax.swing.JPanel();
		jLabelTitle = new javax.swing.JLabel();
		jTextFieldTitle = new javax.swing.JTextField();
		jLabelSubtitle = new javax.swing.JLabel();
		jTextFieldSubtitle = new javax.swing.JTextField();
		jLabelImage1 = new javax.swing.JLabel();
		jTextFieldImage1 = new javax.swing.JTextField();
		jLabelImage2 = new javax.swing.JLabel();
		jTextFieldImage2 = new javax.swing.JTextField();
		jButtonOpenFileImage1 = new javax.swing.JButton();
        jButtonOpenFileImage2 = new javax.swing.JButton();
		jLabelAuthor = new javax.swing.JLabel();
		jTextFieldAuthor = new javax.swing.JTextField();
		jLabelDate = new javax.swing.JLabel();
		jTextFieldDate = new javax.swing.JTextField();
		jButtonOpen = new javax.swing.JButton();
		jButtonCancel = new javax.swing.JButton();

		jPanelSelectTB.setBorder(javax.swing.BorderFactory
				.createTitledBorder(this.uimanager.getTranslation("txtCajetines")));

		jListTB.setModel(new DefaultListModel());
		jListTB.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                jListTBValueChanged(evt);
            }
        });
		jScrollPaneTB.setViewportView(jListTB);
		
		jPanelView.setBorder(javax.swing.BorderFactory.createEtchedBorder());

		javax.swing.GroupLayout jPanelViewLayout = new javax.swing.GroupLayout(jPanelView);
        jPanelView.setLayout(jPanelViewLayout);
        jPanelViewLayout.setHorizontalGroup(
            jPanelViewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 218, Short.MAX_VALUE)
        );
        jPanelViewLayout.setVerticalGroup(
            jPanelViewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 160, Short.MAX_VALUE)
        );
		
        javax.swing.GroupLayout jPanelSelectTBLayout = new javax.swing.GroupLayout(jPanelSelectTB);
        jPanelSelectTB.setLayout(jPanelSelectTBLayout);
        jPanelSelectTBLayout.setHorizontalGroup(
            jPanelSelectTBLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelSelectTBLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPaneTB, javax.swing.GroupLayout.PREFERRED_SIZE, 253, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
                .addComponent(jPanelView, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanelSelectTBLayout.setVerticalGroup(
            jPanelSelectTBLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelSelectTBLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanelSelectTBLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanelView, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPaneTB, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE))
                .addContainerGap())
        );

		jPanelComponents.setBorder(javax.swing.BorderFactory
				.createTitledBorder(this.uimanager.getTranslation("txtComponentes")));

		jLabelTitle.setText(this.uimanager.getTranslation("txtTitulo"));

		jTextFieldTitle.setEnabled(false);

		jLabelSubtitle.setText(this.uimanager.getTranslation("txtSubtitulo"));

		jTextFieldSubtitle.setEnabled(false);

		jLabelImage1.setText(this.uimanager.getTranslation("txtImagen1"));

		jTextFieldImage1.setEnabled(false);

		jLabelImage2.setText(this.uimanager.getTranslation("txtImagen2"));

		jTextFieldImage2.setEnabled(false);

		jLabelAuthor.setText(this.uimanager.getTranslation("txtAutor"));

		jTextFieldAuthor.setEnabled(false);

		jLabelDate.setText(this.uimanager.getTranslation("txtFecha"));

		jTextFieldDate.setEnabled(false);
		
		jButtonOpenFileImage1.setText(this.uimanager.getTranslation("txtSelectImagen1"));
		jButtonOpenFileImage1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonOpenFileImage1ActionPerformed(evt);
            }
        });

	    jButtonOpenFileImage2.setText(this.uimanager.getTranslation("txtSelectImagen2"));
	    jButtonOpenFileImage2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonOpenFileImage2ActionPerformed(evt);
            }
        });
	    
	    javax.swing.GroupLayout jPanelComponentsLayout = new javax.swing.GroupLayout(jPanelComponents);
        jPanelComponents.setLayout(jPanelComponentsLayout);
        jPanelComponentsLayout.setHorizontalGroup(
            jPanelComponentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelComponentsLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelComponentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelImage1)
                    .addComponent(jLabelImage2)
                    .addComponent(jLabelAuthor)
                    .addComponent(jLabelDate)
                    .addComponent(jLabelSubtitle)
                    .addComponent(jLabelTitle))
                .addGap(14, 14, 14)
                .addGroup(jPanelComponentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextFieldDate, javax.swing.GroupLayout.DEFAULT_SIZE, 438, Short.MAX_VALUE)
                    .addComponent(jTextFieldAuthor, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 438, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelComponentsLayout.createSequentialGroup()
                        .addGroup(jPanelComponentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jTextFieldImage1, javax.swing.GroupLayout.DEFAULT_SIZE, 315, Short.MAX_VALUE)
                            .addComponent(jTextFieldImage2, javax.swing.GroupLayout.DEFAULT_SIZE, 315, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanelComponentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jButtonOpenFileImage2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButtonOpenFileImage1)))
                    .addComponent(jTextFieldSubtitle, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 438, Short.MAX_VALUE)
                    .addComponent(jTextFieldTitle, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 438, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanelComponentsLayout.setVerticalGroup(
            jPanelComponentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelComponentsLayout.createSequentialGroup()
                .addGroup(jPanelComponentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldTitle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelTitle))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelComponentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldSubtitle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelSubtitle))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelComponentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldImage1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelImage1)
                    .addComponent(jButtonOpenFileImage1))
                .addGap(8, 8, 8)
                .addGroup(jPanelComponentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldImage2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelImage2)
                    .addComponent(jButtonOpenFileImage2))
                .addGap(8, 8, 8)
                .addGroup(jPanelComponentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldAuthor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelAuthor))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelComponentsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelDate)
                    .addComponent(jTextFieldDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

		jButtonOpen.setText(this.uimanager.getTranslation("txtAbrir"));
		jButtonOpen.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButtonOpenActionPerformed(evt);
			}
		});

		jButtonCancel.setText(this.uimanager.getTranslation("txtCancelar"));
		jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButtonCancelActionPerformed(evt);
			}
		});

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanelSelectTB, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jButtonOpen)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonCancel)
                        .addGap(193, 193, 193))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanelComponents, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanelSelectTB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelComponents, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonOpen)
                    .addComponent(jButtonCancel))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
		setBoxToFrames(tbToFframes);
		
	}// </editor-fold>//GEN-END:initComponents

	/**
	 * This method is called when a new TitleBlock is selected from the list.
	 * It changes the properties of the fields, depending on whether they are present in the template of the TitleBlock or not.
	 * @param evt
	 */
	 private void jListTBValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jListTBValueChanged
	    	
		 File file=new File(jListTB.getSelectedValue().toString());
	    	if (tbToFframes.hasTags(file)){
	        	
	    		if(tbToFframes.hasThisTag("title")) {
	    			jTextFieldTitle.setEnabled(true);
	        		jTextFieldTitle.setBackground(Color.white);
	    		} else {
	        		jTextFieldTitle.setEnabled(false);
	        		jTextFieldTitle.setBackground(Color.gray);
	        	}
	        	
	    		if(tbToFframes.hasThisTag("subtitle")) {
	    			jTextFieldSubtitle.setEnabled(true);
	        		jTextFieldSubtitle.setBackground(Color.white);
	    		} else {
	    			jTextFieldSubtitle.setEnabled(false);
	        		jTextFieldSubtitle.setBackground(Color.gray);
	        	}
	    		
	    		if(tbToFframes.hasThisTag("picture1")) {
	    			jTextFieldImage1.setEnabled(true);
	        		jTextFieldImage1.setBackground(Color.white);
	        		jButtonOpenFileImage1.setEnabled(true);
	    		} else {
	    			jTextFieldImage1.setEnabled(false);
	        		jTextFieldImage1.setBackground(Color.gray);
	        		jButtonOpenFileImage1.setEnabled(false);
	        	}
	    		
	    		if(tbToFframes.hasThisTag("picture2")) {
	    			jTextFieldImage2.setEnabled(true);
	    			jTextFieldImage2.setBackground(Color.white);
	    			jButtonOpenFileImage2.setEnabled(true);
	    		} else {
	    			jTextFieldImage2.setEnabled(false);
	    			jTextFieldImage2.setBackground(Color.gray);
	    			jButtonOpenFileImage2.setEnabled(false);
	    		}
	        	
	    		if(tbToFframes.hasThisTag("author")) {
	    			jTextFieldAuthor.setEnabled(true);
	    			jTextFieldAuthor.setBackground(Color.white);
	    		} else {
	    			jTextFieldAuthor.setEnabled(false);
	    			jTextFieldAuthor.setBackground(Color.gray);
	    		}	
	        	
	    		if(tbToFframes.hasThisTag("date")) {
	    			jTextFieldDate.setEnabled(true);
	    			jTextFieldDate.setBackground(Color.white);
	    		} else {
	    			jTextFieldDate.setEnabled(false);
	    			jTextFieldDate.setBackground(Color.gray);
	    		}	
	        	
	    		jPanelComponents.setEnabled(true);
	    		
	    	} else {
	    		jTextFieldTitle.setEnabled(false);
	        	jTextFieldSubtitle.setEnabled(false);
	        	jTextFieldImage1.setEnabled(false);
	        	jTextFieldImage2.setEnabled(false);
	        	jTextFieldAuthor.setEnabled(false);
	        	jTextFieldDate.setEnabled(false);
	        	jTextFieldTitle.setBackground(Color.gray);
	        	jTextFieldSubtitle.setBackground(Color.gray);
	        	jTextFieldImage1.setBackground(Color.gray);
	        	jTextFieldImage2.setBackground(Color.gray);
	        	jTextFieldAuthor.setBackground(Color.gray);
	        	jTextFieldDate.setBackground(Color.gray);
	        	jPanelComponents.setEnabled(false);
	        }
//	    	tbToFframes.drawInPanel(jPanelView);
	    	jPanelView.repaint();//invalidate();
	    }//GEN-LAST:event_jListTBValueChanged
	
	
	/**
	 * This method opens the TitleBlock selected, and fill the fields with the text inserted.
	 * @param evt
	 */
	private void jButtonOpenActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jButtonOpenActionPerformed
		// Aceptar
    	HashMap<String, String> selecteds=new HashMap<String, String>();
    	selecteds.put("title", jTextFieldTitle.getText());
    	selecteds.put("subtitle", jTextFieldSubtitle.getText());
    	selecteds.put("picture1", jTextFieldImage1.getText());
    	selecteds.put("picture2", jTextFieldImage2.getText());
    	selecteds.put("author", jTextFieldAuthor.getText());
    	selecteds.put("date", jTextFieldDate.getText());
    	
    	tbToFframes.gvbToFrames(new File(jListTB.getSelectedValue().toString()),selecteds);
    	
    	applicationManager.getUIManager().closeWindow(this);
    	manager.getLayout().getLayoutControl().refresh();
	}// GEN-LAST:event_jButtonOpenActionPerformed

	/**
	 * This method closes the window
	 * @param evt
	 */
	private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jButton3ActionPerformed
		// Cancelar
		applicationManager.getUIManager().closeWindow(this);
	}// GEN-LAST:event_jButton3ActionPerformed


	/**
	 * This method allows to select the path of the image 1
	 * @param evt
	 */
	private void jButtonOpenFileImage1ActionPerformed(java.awt.event.ActionEvent evt) {
		String imagePath = selectImage();	
		jTextFieldImage1.setText(imagePath);
	}
	
	/**
	 * This method allows to select the path of the image 2
	 * @param evt
	 */
	private void jButtonOpenFileImage2ActionPerformed(java.awt.event.ActionEvent evt) {	
		String imagePath = selectImage();		
		jTextFieldImage2.setText(imagePath);
	}
	
	/**
	 * This method opens a FileChooser window to select an image
	 * @return
	 */
	private String selectImage() {
		String imagePath = null;
		JFileChooser fc = new JFileChooser(); 
		javax.swing.filechooser.FileFilter def = new javax.swing.filechooser.FileFilter() {

			@Override
			public String getDescription() {
				return JOpenTBPanel.this.uimanager.getTranslation("txtImage");
			}

			@Override
			public boolean accept(File f) {
				return f.getAbsolutePath().toLowerCase().endsWith(".gif") || 
						f.getAbsolutePath().toLowerCase().endsWith(".png") ||
						f.getAbsolutePath().toLowerCase().endsWith(".jpeg") ||
						f.getAbsolutePath().toLowerCase().endsWith(".jpg") ||
						f.getAbsolutePath().toLowerCase().endsWith(".bmp") ||
						f.getAbsolutePath().toLowerCase().endsWith(".svg");
			}
		};
		fc.setMultiSelectionEnabled(false);
		fc.setAcceptAllFileFilterUsed(false);
		fc.addChoosableFileFilter(def);
		if(fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { 
			imagePath = fc.getSelectedFile().getAbsolutePath();
	    } // TODO add your handling code here:
		
		return imagePath;
	}
	
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
	 */
	public WindowInfo getWindowInfo() {
		WindowInfo wi = new WindowInfo(WindowInfo.MODALDIALOG
				| WindowInfo.RESIZABLE);
		wi.setTitle(this.uimanager.getTranslation("save_box"));
		wi.setWidth(600);
		wi.setHeight(450);
		return wi;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.iver.andami.ui.mdiManager.IWindow#getWindowProfile()
	 */
	public Object getWindowProfile() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ITBManager getTBManager() {
		return manager;
	}

	/**
	 * This method converts the box into frames
	 * @param btf
	 */
	private void setBoxToFrames(ITBToFFrame btf) {
		this.tbToFframes=btf;
		Object[] items=tbToFframes.getItems();
		for (int j = 0; j < items.length; j++) {
			((DefaultListModel)jListTB.getModel()).addElement(items[j]);
		}
	}
	

	private class JPanelPreview extends JPanel{

		@Override
		protected void paintComponent(Graphics g) {
			super.paintComponent(g);
			tbToFframes.drawInPanel(jPanelView,g);
		}
		
	}

}
